{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "a = \"ace\"\n",
    "print(len(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['s', 'uden', ',my caobinxin']\n",
      "s\n",
      "uden\n",
      ",my caobinxin\n"
     ]
    }
   ],
   "source": [
    "a = \"student,my caobinxin\"\n",
    "b = a.split('t')\n",
    "print(b)\n",
    "\n",
    "for i in b:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "STUDENT,MY CAOBINXIN\n"
     ]
    }
   ],
   "source": [
    "print(a.upper())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "def func1():\n",
    "    a = 9\n",
    "    a += 8\n",
    "    print(a)\n",
    "    \n",
    "func1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "0\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "def func(add=0, b=0, c=0):\n",
    "    print(add)\n",
    "    print(b)\n",
    "    print(c)\n",
    "\n",
    "func()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "3\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "func(c=2, b=3, add=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "func(b=4, c=2, add=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "func(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (<ipython-input-10-40dea1f1a813>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-10-40dea1f1a813>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    func(b=2, c=3, 3)\u001b[0m\n\u001b[0m                  ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "func(b=2, c=3, 3) # 在顺序被打乱后必须使用关键字参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "i = 100\n",
    "def fun3():\n",
    "    i = 5\n",
    "a = fun3()\n",
    "print(a)\n",
    "\n",
    "print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "i = 100\n",
    "def fun3():\n",
    "    global i # 使用全局变量\n",
    "    i = 5\n",
    "a = fun3()\n",
    "print(a)\n",
    "\n",
    "print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4, 5, 20)\n"
     ]
    }
   ],
   "source": [
    "def test2(i, j):\n",
    "    k = i*j\n",
    "    return (i, j, k)\n",
    "\n",
    "a = test2(4, 5)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 5, 20]\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "def test2(i, j):\n",
    "    k = i*j\n",
    "    return [i, j, k]\n",
    "\n",
    "a = test2(4, 5)\n",
    "print(a)\n",
    "\n",
    "a, b, c = test2(4,5)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function d in module __main__:\n",
      "\n",
      "d(i, j)\n",
      "    这个函数实现了一个乘法运算。\n",
      "    函数会返回一个乘法运算的结果。\n",
      "\n",
      "12\n"
     ]
    }
   ],
   "source": [
    "\n",
    "def d(i, j):\n",
    "    '''\n",
    "    这个函数实现了一个乘法运算。\n",
    "    函数会返回一个乘法运算的结果。\n",
    "    '''\n",
    "    k = i * j\n",
    "    return k\n",
    "help(d)\n",
    "\n",
    "\n",
    "\n",
    "a = d(3,4)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
